package com.cszjzx.member.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import com.cszjzx.member.po.*;
import com.cszjzx.member.service.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@SuppressWarnings("serial")
public class OptionsAction extends ActionSupport{
	private String department;
	private MajorServiceImpl majorService = new MajorServiceImpl();
	private DepartmentServiceImpl departmentService = new DepartmentServiceImpl();

	public String getDepartment() {
		return department;
	}

	public void setDepartment(String department) {
		this.department = department;
	}
	
	public String major(){
		List<Major> majors = majorService.getMajorsByDepartmentName(department);
		String majorOptions= "<option value=''>请选择</option>";
		for(Major major:majors){ 
			majorOptions+="<option value="+major.getName()+">"+major.getName()+"</option>"; 
		}
		HttpServletResponse s = ServletActionContext.getResponse();
		try {
			s.setContentType("text/html; charset=utf-8");
			s.getWriter().write(majorOptions);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return NONE;
	}
	
	public String department(){
		List<Department>  departments = departmentService.getDepartments();
		String departmnetOptions= "<option value=''>请选择</option>";
		for(Department department:departments){ 
			departmnetOptions+="<option value="+department.getName()+">"+department.getName()+"</option>"; 
		}
		HttpServletResponse s = ServletActionContext.getResponse();
		try {
			s.setContentType("text/html; charset=utf-8");
			s.getWriter().write(departmnetOptions);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return NONE;
	}
}
